﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

namespace BookStore.Models
{
    public class BillRentModel
    {
        private string connectionString;
        private SqlConnection connect;

        public BillRentModel()
        {
            connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
            connect = new SqlConnection(connectionString);
        }

        public void insertNewBill(string[] data)
        {
            connect.Open();
            string sqlquery = "INSERT INTO Bill_Rent (shipping_detail_id,payment_id,quantity,total_bill_price,created_date,user_id,bill_code,deposit,updated_date,status,check_quantity) VALUES (N'" + data[0] + "',N'" + data[1] + "',N'" + data[2] + "',N'" + data[3] + "',N'" + data[4] + "',N'" + data[5] + "',N'" + data[6] + "',N'" + data[7] + "',N'" + data[8] + "',N'" + data[9] + "',0)";
            SqlCommand scd = new SqlCommand(sqlquery, connect);
            scd.ExecuteNonQuery();
            connect.Close();
        }
        public string getLastIdBill()
        {
            string id = "";
            connect.Open();
            string sqlquery = "SELECT max(bill_id) FROM Bill_Rent";
            SqlCommand scd = new SqlCommand(sqlquery, connect);
            SqlDataReader reader = scd.ExecuteReader();
            if (reader.Read())
            {
                id = reader[0].ToString();
            }
            connect.Close();
            return id;
        }
    }
}
